<?php
declare(strict_types= 1);

use app\admin\model\ArcModel;
use app\admin\model\Category;

use function PHPUnit\Framework\assertTrue;
use app\admin\service\CategoryServiceImpl;
use app\admin\service\UserServiceImpl;
use think\App;
use think\facade\Db;

class CategoryTest extends PHPUnit\Framework\TestCase{
    public static function setUpBeforeClass(): void
    {
        $http = (new App())->http;

        $response = $http->run();
    }

    function tearDown(): void
    {
        assertTrue(true);
    }

    public function testModel()
    {
        $model = Category::findOrEmpty(1);
        echo class_basename($model->model); 
        // var_dump($model->model->name);
        // print($model->model->name);
    }
    public function testAdd()
    {
        try {
            //code...
            $service = new CategoryServiceImpl();
            $service->add("ccc",2,2);
        } catch (\Throwable $th) {
            //throw $th;
            print("error");
            print($th->getMessage());
        }
    }

    public function testEdit()
    {
        try {
            //code...
            $service = new CategoryServiceImpl();
            $service->edit(2,"fff",2,1);
        } catch (\Throwable $th) {
            //throw $th;
            print("error");
            print($th->getMessage());
        }
    }

    public function testDb()
    {
        Db::startTrans();
        try {
            $userservice = new UserServiceImpl();
            $userservice->register("qqqqq111","wwwwww");
            $userservice->register("qqqqq122","wwwwww");
            $userservice->register("qqqqq133","wwwwww");
            // $userservice->delete(6);
            // $userservice->delete(7);
            // $userservice->delete(8);
            // $userservice->delete(9);
            // 提交事务
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            print("error");
            Db::rollback();
        }
    }

    
}
